﻿namespace KeRui.Common
{
    using System;

    public class MailSend
    {
        public static string Single(string resEmail, string Subject, string Body)
        {
            return Single(resEmail, Subject, Body, ConfigHelper.GetConfigString("EmailServer"), ConfigHelper.GetConfigString("EmailAccount"), ConfigHelper.GetConfigString("EmailPassword"), ConfigHelper.GetConfigString("EmailSender"), ConfigHelper.GetConfigInt("EmailPort", 0x19));
        }

        public static string Single(string resEmail, string Subject, string Body, string EmailServer, string EmailAccount, string EmailPassword, string EmailSender, int MailDomainPort)
        {
            SmtpMail mail = new SmtpMail();
            try
            {
                mail.RecipientName = resEmail;
                mail.AddRecipient(new string[] { resEmail });
                mail.MailDomainPort = MailDomainPort;
                mail.From = EmailAccount;
                mail.FromName = EmailSender;
                mail.Html = bool.Parse("true");
                mail.Subject = Subject;
                mail.Body = Body;
                mail.MailDomain = EmailServer;
                mail.MailServerUserName = EmailAccount;
                mail.MailServerPassWord = EmailPassword;
                mail.Send();
                if ((mail.ErrorMessage == null) || (mail.ErrorMessage.ToString() == ""))
                {
                    return "ok";
                }
                return mail.ErrorMessage.ToString();
            }
            catch (Exception exception)
            {
                return exception.Message;
            }
        }
    }
}

